<template>
  <div id="">
    <headerbox :headerTitle="'登录'" :hasBack="true"></headerbox>
    <ul class="formList">
      <li>
        <span>手机号</span>
        <input type="text" name="" v-model="phone" placeholder="输入正确的手机号">
      </li>
      <li>
        <span>密码</span>
        <input type="text" name="" v-model="pwd" placeholder="输入正确的手机号">
      </li>
    </ul>

    <div class="p10 mt10" align="right">
      <router-link :to="{ name: 'register'}" class="tips">
        还没有账号，前往注册
      </router-link>

    </div>
    <div class="fixedButtom">
      <button type="button" name="button" class="blockButton" @click="loginBtn">登录</button>
    </div>
  </div>
</template>
<script>
import {loginPost} from '@/utils/ajaxRequest.js';
import { mobileTest } from '@/utils/util.js';
import {postRequest} from '@/utils/network.js';
export default {
  name: "",
  data: () => ({
    phone:'',
    pwd:'',
  }),
  methods: {
    loginBtn() {
      let self = this;
      if(self.phone=='') {
        self.toast('请填写手机号码');
        return false;
      }else{
        if(!mobileTest(self.phone)) {
          self.toast('请输入正确的手机号');
          return false;
        }
      }
      if(self.pwd=='') {
        self.toast('请输入密码');
        return false;
      }
      let loginParam = {
        phone: this.phone,
        pwd: this.pwd,
      }
      loginPost(loginParam).then(res=>{
        console.log(res);
        if(res){
          this.toast(res.data.msg);
          window.localStorage.setItem('xlyd_loginInfo',JSON.stringify(res.data.result));   //登录的用户信息存入本地缓存
          this.$router.go(-1);  //返回上一页
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
